package net.bingosoft.common.struts;

import java.io.Serializable;
import java.util.List;

import javax.servlet.http.HttpServletRequest;

import net.bingosoft.common.util.AutoArrayList;

import org.apache.struts.action.ActionMapping;
import org.apache.struts.upload.FormFile;
/**
 * 2007-9-14 下午01:00:32
 * Author:yangdongyu(yangdy@bingosoft.net)
 * ReadMe:支持多文件上传的form
 * ChangeLog:
 */
public class MultiUploadForm extends BaseActionForm {
	private static final long serialVersionUID = 1L;
	/**
	 * 指定form的验证方式,默认根据form名称进行验证
	 */
	private boolean usePathValidation = false;
	/**
	 * 要上传的文件列表
	 */
	private List<UploadFile> uploadedFiles = new AutoArrayList<UploadFile>(UploadFile.class);
	/**
	 * 默认构造函数
	 */
	public MultiUploadForm(){}
    /**
     * 能够指定验证方式的构造函数
     * @param usePathValidation
     */
	protected MultiUploadForm(boolean usePathValidation){
		this.usePathValidation = usePathValidation;
	}
	public List <UploadFile>getUploadedFiles() {
		return uploadedFiles;    
	}    

	public void setUploadedFiles(List<UploadFile> files) {
		this.uploadedFiles = files;
	}

	/* (non-Javadoc)
	 * @see org.apache.struts.validator.ValidatorForm#getValidationKey(org.apache.struts.action.ActionMapping, javax.servlet.http.HttpServletRequest)
	 */
	@Override
	public String getValidationKey(ActionMapping mapping, HttpServletRequest request) {
		return usePathValidation ? mapping.getPath(): mapping.getAttribute();
	}

	/**
	 * 2007-9-14 下午01:04:07
	 * Author:yangdongyu(yangdy@bingosoft.net)
	 * ReadMe:由于FormFile 无法实例化,就在外面又包了一层:)
	 * ChangeLog:
	 */
	public static class UploadFile implements Serializable {
		private static final long serialVersionUID = 1L;
		private FormFile file;
		public FormFile getFile() {
			return file;
		}
		public void setFile(FormFile file) {
			this.file = file;
		}
	}
} 



